<template>
    <div style="height:100%;">
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div class="equipment-right-select"
                 @click="companyPropShow = true"
                 v-if="userInfo.departsir != '1'">
                <span>{{deptname}}</span>
                <i class="iconfont icon-jinru rightmsg"></i>
            </div>
            <div class="equipment-right-select"
                 v-else>
                <span>{{deptname}}</span>
            </div>
        </div>
        <div class="cut-off-rule"></div>
        <noData v-if="list.length == 0"></noData>
        <div class="betterscrollWrapper">
            <vue-better-scroll class="betterscroll"
                               ref="scroll"
                               :scrollbar="scrollbarObj"
                               :pullDownRefresh="pullDownRefreshObj"
                               :pullUpLoad="pullUpLoadObj"
                               :startY="parseInt(startY)"
                               @pullingDown="onPullingDown"
                               @pullingUp="onPullingUp">
                <ul class="recursive-ul">
                    <li v-for="(item,index) in list"
                        :key="index">
                        <div class="item"
                             @click="itemOpen(item)">
                            <p>{{item.ProjectName}}</p>
                            <p>
                                <span>{{item.OrganUserName}}（{{item.OrganPost}}）</span>
                                <x-icon type="ios-arrow-right"
                                        size="20"
                                        fill="#999"
                                        v-show="!item.open"></x-icon>
                                <x-icon type="ios-arrow-down"
                                        size="20"
                                        fill="#999"
                                        v-show="item.open"></x-icon>
                            </p>
                        </div>
                        <ul class="recursive-ul"
                            v-show="item.open">
                            <li>
                                <div class="form-item form-item-style1">
                                    <div class="label-title">
                                        <label>联系电话</label>
                                    </div>
                                    <div>
                                        <p>{{item.OrganTel}}</p>
                                    </div>
                                </div>
                            </li>
                            <li>
                                <div class="form-item form-item-style1">
                                    <div class="label-title">
                                        <label>备注</label>
                                    </div>
                                    <div>
                                        <p>{{item.OrganRemark}}</p>
                                    </div>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </vue-better-scroll>
        </div>
        <activityCompany :selectCompany="selectCompany"
                         :companyPropShow="companyPropShow"></activityCompany>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import activityCompany from '@/commonComponents/activityCompany'
import VueBetterScroll from 'vue2-better-scroll'
export default {
    name: 'rescueStructure',
    components: {
        VueBetterScroll,
        myMenu,
        activityCompany
    },
    data () {
        return {
            userInfo: {},
            // dropDown: false
            // 这个配置可以开启滚动条，默认为 false。当设置为 true 或者是一个 Object 的时候，都会开启滚动条，默认是会 fade 的
            scrollbarObj: {
                fade: true
            },
            // 这个配置用于做下拉刷新功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启下拉刷新，可以配置顶部下拉的距离（threshold） 来决定刷新时机以及回弹停留的距离（stop）
            pullDownRefreshObj: {
                threshold: 90,
                stop: 40
            },
            // 这个配置用于做上拉加载功能，默认为 false。当设置为 true 或者是一个 Object 的时候，可以开启上拉加载，可以配置离底部距离阈值（threshold）来决定开始加载的时机
            pullUpLoadObj: {
                threshold: 0,
                txt: {
                    more: '加载更多',
                    noMore: '没有更多数据了'
                }
            },
            startY: 0, // 纵轴方向初始化位置
            scrollToX: 0,
            scrollToY: 0,
            scrollToTime: 700,
            companyPropShow: false,
            deptname: '',
            deptId: '',
            listAllCount: 0,
            listCount: 0,
            pageIndex: 0,
            list: []
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.deptname = this.userInfo.deptname
        this.deptId = this.userInfo.deptid
        this.onPullingDown()
    },
    methods: {
        itemOpen (item) {
            this.$set(item, 'open', !item.open)
        },
        onPullingDown () {
            // 模拟下拉刷新
            this.listCount = 0
            this.pageIndex = 0
            this.list = []
            this.getData()
        },
        onPullingUp () {
            this.pageIndex++
            this.getData()
        },
        getData () { // 获取通知公告
            var params = {
                'business': 'GetEmergencyOrganList',
                'data': {
                    'DepartId': this.deptId
                },
                'pageIndex': this.pageIndex,
                'pageSize': 10,
                'userId': this.userInfo.userid
            }

            this.$axiosAjax.getConfigJson(params)
                .then((res) => {
                    if (res.data.code === 0) {
                        this.list = this.list.concat(res.data.data)
                        this.listAllCount = res.data.count
                        this.listCount = this.list.length
                    }
                    if (this.listCount < this.listAllCount) {
                        this.$refs.scroll.forceUpdate(true)
                    } else {
                        this.$refs.scroll.forceUpdate(false)
                    }
                }).catch((response) => {
                })
        },
        selectCompany (item) {
            this.companyPropShow = false
            this.deptname = item.deptName
            this.deptId = item.deptId
            this.onPullingDown()
        }
    }
}
</script>
<style scoped>
.betterscrollWrapper {
    position: absolute;
    top: 65px;
    left: 0;
    right: 0;
    bottom: 0;
}
.betterscroll {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}
.recursive-ul .item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 20px;
    padding-left: 20px;
    border-bottom: 1px solid #f4f4f4;
}
.item + .recursive-ul {
    padding-left: 20px;
}
.recursive-ul .item > p {
    line-height: 40px;
    font-size: 14px;
    color: #333;
}
.recursive-ul .item > p:last-child {
    display: flex;
    align-items: center;
}
.recursive-ul .item > p:first-child {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recursive-ul span {
    color: #999;
}
/* .recursive-ul .recursive-ul li:last-child .form-item {
    border-bottom: none;
}
.recursive-ul .recursive-ul {
    border-bottom: 1px solid #f4f4f4;
} */
</style>
